package com.wisdudu.frame.support.util;

import java.util.regex.Pattern;

/**
 * Created by qyf on 2016/9/1.
 */

public class PinyinUtil {
    /**
     * 获取拼音的首字母（大写）
     *
     * @param pinyin
     * @return
     */
    public static String getFirstLetter(final String pinyin) {
        String c = pinyin.substring(0, 1);
        Pattern pattern = Pattern.compile("^[A-Za-z]+$");
        if (pattern.matcher(c).matches()) {
            return c.toLowerCase();
        } else {
            return "Z";
        }
    }

    public static String getFirstLetter(final String pinyin, boolean isUppeerCase) {
        String c = pinyin.substring(0, 1);
        Pattern pattern = Pattern.compile("^[A-Za-z]+$");
        if (pattern.matcher(c).matches()) {
            return isUppeerCase?c.toUpperCase():c;
        } else {
            return "{";
        }
    }

}
